import {onMounted, ref} from "vue";

// 吸顶元素状态处理
export function useSticky() {
    const isFixed = ref(false);

    function onStickyScroll(params: any) {
        isFixed.value = params.isFixed && params.scrollTop > 0;
    }

    return {
        isFixed,
        onStickyScroll,
    }
}

// 元素高度监听
export function useElementHeight() {
    const elRefName = ref();
    const elHeight = ref(0);

    // 计算高度
    function onChangeHeight() {
        const el: any = elRefName.value
        if (el instanceof HTMLElement) {
            elHeight.value = el.offsetHeight
        }
    }

    onMounted(() => {
        onChangeHeight();
    })
    return {
        elRefName,
        elHeight,
        onChangeHeight,
    }
}
